/*
 * @Author: c
 * @Date: 2024-01-09 12:24:20
 * @LastEditTime: 2024-03-28 08:19:39
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\album\album.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, ParseIntPipe, Post, Put, Query, Req } from '@nestjs/common';
import { SkipAuth } from 'src/core/system/auth/constants';
import { AlbumService } from './album.service';
import { AlbumForm, FavoriteForm } from './dto/create-album.dto';
import { AlbumPageQuery } from './dto/search-album.dto';

@Controller('album')
export class AlbumController {
  constructor(private readonly albumService: AlbumService) { }



  /**
  * 专辑-我收藏的专辑
  * @param pageDto 
  * @returns 
  */
  @Get("favorite")
  getFavorite(@Req() req, @Query() pageDto: AlbumPageQuery) {
    return this.albumService.myfavorite(req.user, pageDto);
  }

  /**
    * 专辑-新增-我收藏的专辑
    * @param songForm 
    * @returns 
    */
  @Post("favorite")
  createFavorite(@Req() req, @Body() songForm: FavoriteForm) {
    return this.albumService.createfavorite(req.user, songForm);
  }

  /**
    * 专辑-删除-我收藏的专辑
    * @param songForm 
    * @returns 
    */
  @Delete("favorite")
  deletefavorite(@Req() req, @Body() songForm: FavoriteForm) {
    return this.albumService.deletefavorite(req.user, songForm);
  }


  /**
     * 专辑-分页查询
     * @param pageDto 
     * @returns 
     */
  @SkipAuth()
  @Get("page")
  getPage(@Req() req, @Query() pageDto: AlbumPageQuery) {
    return this.albumService.findAll(req.user, pageDto);
  }
  /**
     * 专辑-秀动发行
     * @param pageDto 
     * @returns 
     */
  @SkipAuth()
  @Get("xdpublish")
  xdpublish(@Req() req, @Query() pageDto: AlbumPageQuery) {
    return this.albumService.xdpublish(req.user, pageDto);
  }
  /**
     * 专辑-分页查询
     * @param pageDto 
     * @returns 
     */
  @Get("options")
  listOptions(@Req() req, @Query() pageDto: AlbumPageQuery) {
    return this.albumService.listOptions(req.user, pageDto);
  }




  /**
   * 专辑-新增
   * @param pageDto 
   * @returns 
   */
  @Post()
  saveAlbum(@Body() albumForm: AlbumForm) {

    return this.albumService.saveAlbum(albumForm); //必须return 不然报错终止整个运行的进程
  }


  /**
  * 专辑-单条表单数据
  * @param typeCode 
  * @returns 
  */
  @SkipAuth()
  @Get(":id/form")
  getAlbumFormData(@Req() req: any,
    @Param('id', ParseIntPipe) id
  ) {
    return this.albumService.getAlbumFormData(req.user, id);
  }



  /**
   * 专辑-修改
   * @param albumForm 
   * @returns 
   */
  @Put(':albumId')
  async updateAlbum(@Req() req, @Param('albumId', ParseIntPipe) albumId: number, @Body() albumForm: AlbumForm) {
    const user = req.user;
    return await this.albumService.update(user, albumId, albumForm); //必须return 不然报错终止整个运行的进程
  }

  /**
   * 专辑-删除
   * @param id
   * @returns 
   */
  @Delete(':ids')
  remove(@Param('ids', ParseArrayPipe) ids: number[]) {
    return this.albumService.removeByIds(ids);
  }
}
